<template>
  <div class="home">
    <HeaderView></HeaderView>
    <NavN v-show="isShow" class="nav-sticky"></NavN>
    <Nav v-show="!isShow" class="xx" ref="nav"></Nav>
    <div class="content">
      <div class="content-center">
        <router-view />
      </div>
    </div>
    <FooterView></FooterView>
  </div>
</template>

<script>
import HeaderView from "@/components/HeaderView.vue";
import FooterView from "@/components/FooterView.vue";
import Nav from "@/components/NavView.vue";
import NavN from "@/components/NavNoView.vue";
export default {
  name: "HomeView",
  components: { HeaderView, FooterView, Nav, NavN },
  data() {
    return {
      isShow: false,
    };
  },
  mounted() {
    // console.log(this.$refs.home)
    window.addEventListener("scroll", this.toFix, true);
  },
  methods: {
    toFix() {
      var scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop;
      var ofH =
        document.querySelector(".xx").offsetTop +
        document.querySelector(".xx").offsetHeight;
      const res = scrollTop > ofH ? true : false;
      this.isShow = res;
    },
  },
};
</script>
<style lang="less" scoped>
.nav-sticky {
  position: sticky;
  top: 0;
  width: 100%;
  z-index: 10000;
}
.active {
  color: black;
  text-decoration: none;
}
.active:hover {
  color: aqua;
}
.blackHeader {
  width: 100%;
  height: 55px;
  background: #333;
  ul {
    width: 650px;
    height: 55px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    margin-left: 900px;
    color: rgba(255, 255, 255, 0.639);
    font-size: 15px;
  }
}
.whiteHeader {
  width: 100%;
  height: 130px;
  background: white;
  position: sticky;
  top: 0;
  .whiteBox {
    width: 1240px;
    height: 130px;
    margin: 0 auto;
    display: flex;
    .rubbit {
      display: flex;
      align-items: center;
      img {
        width: 210px;
        height: 80px;
      }
    }
    .list {
      width: 770px;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: space-around;
    }
    .search {
      width: 160px;
      height: 100%;
      display: flex;
      align-items: center;
      position: relative;
      i {
        position: absolute;
      }
      input {
        width: 100%;
        height: 30px;
        border: none;
        background: transparent;
        border-bottom: 1px solid rgba(128, 128, 128, 0.666);
        padding-left: 25px;
        box-sizing: border-box;
      }
    }
    .shopping {
      display: flex;
      align-items: center;
      font-size: 28px;
      padding-left: 20px;
      box-sizing: border-box;
    }
  }
}
.content {
  width: 100%;
  .content-center {
    width: 1240px;
    margin: 0 auto;
  }
}
</style>
